<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../vue.js"></script>
</head>

<body>
  <div id="app">
    <button @click="changePerson">修改对象</button>
    <div>person--->{{person}}</div>
  </div>
  <script>
    new Vue({
      el: "#app",
      data() {
        return {
          person: {
            name: "余海海",
            age: 30,

          },
        };
      },
      methods: {
        changePerson() {
          /* 
              因为vue2响应式原理的底层原理无法监听对象的删除和新增
              vue2新提供了两个方法 可以响应式的新增和删除对象的属性(Vue.set()和Vue.delete() 或者this.$set()和this.#delete())

          */

          // 新增
          // this.$set(this.person, "sex", "男");
          // Vue.set(this.person, "sex", "男");

          console.log(this.$set === Vue.set);// true同一个方法放在两个不同的地方

          // 删除
          Vue.delete(this.person, "age");
        }
      }
    });

  </script>
</body>

</html>